﻿<views:NewsReaderPage
    x:Class="NewsReaderApp.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:NewsReaderApp"
    xmlns:views="using:NewsReaderApp.Views"
    xmlns:cvt="using:NewsReaderApp.Helpers"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.BottomAppBar>
        <AppBar x:Name="GlobalAppBar" Padding="10,0,10,0" AutomationProperties.Name="Global App Bar" Opened="HandleAppBarOpened">
            <Grid>
                <StackPanel x:Name="LeftCommands" Orientation="Horizontal"  HorizontalAlignment="Left">
                    <Button Margin="3" Command="{Binding ReloadFromInternetCommand}" 
                        x:Name="Reload" AutomationProperties.Name="Reload From Internet"
                        Style="{StaticResource RefreshAppBarButtonStyle}" HorizontalAlignment="Left"/>

                    <!--Command="{Binding SelectUserFeedsCommand}"-->
                    <Button Margin="3"  
                        x:Name="SelectFeeds" Command="{Binding ShowFeedSelectorCommand}" AutomationProperties.Name="Select News Feeds"
                        Style="{StaticResource MoreAppBarButtonStyle}" HorizontalAlignment="Left"/>
                </StackPanel>
                <StackPanel x:Name="RightCommands" Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button x:Name="OpenInBrowser" Command="{Binding OpenInBrowserCommand}"
                            Margin="3" AutomationProperties.Name="Open In Browser"
                            Style="{StaticResource WorldAppBarButtonStyle}" HorizontalAlignment="Right"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
    <Grid>
        <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
            <Border Style="{StaticResource ContentBorder}">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="ApplicationViewStates">
                        <VisualState x:Name="FullScreenLandscape">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="portrait" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="landscape" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                </ObjectAnimationUsingKeyFrames>

                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snapped" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Filled">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="landscape" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="portrait" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snapped" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="FullScreenPortrait">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="landscape" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="portrait" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snapped" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Snapped">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="landscape" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="portrait" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snapped" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Grid x:Name="LayoutRoot" >
                    <views:LandscapeView x:Name="landscape" />
                    <views:PortraitView x:Name="portrait"/>
                    <Grid x:Name="snapped" Background="#009933" Visibility="Collapsed">
                        <StackPanel VerticalAlignment="Center"   Orientation="Vertical">
                            <Image Source="../Assets/SplashScreen.scale-100.png"/>
                            <Viewbox Margin="5">
                                <TextBlock Text="{StaticResource AppName}" HorizontalAlignment="Center"/>
                            </Viewbox>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Border>
        </UserControl>
        <Border x:Name="feedSelector" 
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource ApplicationPageBackgroundThemeBrush}"  >
            <Border.Resources>
                <Storyboard x:Name="showSelectorStory" FillBehavior="HoldEnd"  >
                    <FadeInThemeAnimation Storyboard.TargetName="feedSelector" />
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="feedSelector"
                                     Storyboard.TargetProperty="Visibility" Duration="0">
                        <DiscreteObjectKeyFrame Value="Visible" KeyTime="0"/>
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlobalAppBar" Storyboard.TargetProperty="IsOpen" Duration="0">
                        <DiscreteObjectKeyFrame Value="false" KeyTime="0"/>
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="portrait" Storyboard.TargetProperty="IsPopupOpen" Duration="0">
                        <DiscreteObjectKeyFrame Value="false" KeyTime="0"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlobalAppBar" Storyboard.TargetProperty="IsEnabled" Duration="0">
                        <DiscreteObjectKeyFrame Value="false" KeyTime="0"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Name="hideSelectorStory" FillBehavior="HoldEnd" >
                    <FadeOutThemeAnimation Storyboard.TargetName="feedSelector"/>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="feedSelector"
                                     Storyboard.TargetProperty="Visibility" Duration="0">
                        <DiscreteObjectKeyFrame Value="Collapsed" KeyTime="0"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlobalAppBar" Storyboard.TargetProperty="IsEnabled" Duration="0">
                        <DiscreteObjectKeyFrame Value="true" KeyTime="0"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>

            </Border.Resources>

            <Border BorderBrush="Black" CornerRadius="10" Margin="50, 100, 50, 150" BorderThickness=".6">
                <views:FeedSelector x:Name="selector"  />
            </Border>
        </Border>
    </Grid>

</views:NewsReaderPage>